﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Data.Services.Client;
using Autorent.Mobile.AutorentMobileService;
using System.ComponentModel;

namespace Autorent.Mobile.Model
{
    public class OrderInfoRepository
    {

        #region GetCarName method

        public delegate void GetCarNameCompletedHandler(string carName);

        public event GetCarNameCompletedHandler GetCarCompleted;

        public void GetAutoNameById(string autoId)
        {
            AutorentMobileServiceClient client = new AutorentMobileServiceClient();
            try
            {
                client.GetCarNameByIdAsync(autoId);
                client.GetCarNameByIdCompleted += new EventHandler<GetCarNameByIdCompletedEventArgs>(client_GetCarNameCompleted);
            }
            catch (Exception ex)
            {
                throw new PhoneModelException("Error while connecting service", ex.InnerException);
            }
        }

        void client_GetCarNameCompleted(object sender, GetCarNameByIdCompletedEventArgs e)
        {
            if (e != null)
                GetCarCompleted(e.Result.ToString());
        }

        #endregion




        public void SetDamage(string damageDescription, int damageCost, string autoId)
        {
            AutorentMobileServiceClient client = new AutorentMobileServiceClient();
            try
            {
                client.AddCarDamageAsync(damageDescription, damageCost, autoId);
            }
            catch (Exception ex)
            {
                throw new PhoneModelException("Error while adding damage", ex.InnerException);
            }
        }



        public void SetReturnDate(DateTime date, string carId)
        {
            AutorentMobileServiceClient client = new AutorentMobileServiceClient();
            try
            {
                client.AddDateReturnAsync(date, carId);
            }
            catch (Exception ex)
            {
                throw new PhoneModelException("Error while adding date", ex.InnerException);
            }
        }



        public void SetGasQuantity(int gasQuantity, string carId)
        {
            AutorentMobileServiceClient client = new AutorentMobileServiceClient();
            try
            {
                client.AddGasQuantityAsync(gasQuantity, carId);
            }
            catch (Exception ex)
            {
                throw new PhoneModelException("Error while adding gas quantity record", ex.InnerException);
            }
        }

    }
}
